def max_m(arr):
    total = sum(arr)
    if total == 0:
        return len(arr)
    max_val = arr[0]
    max_possible = min(len(arr), total // max_val)
    for m in range(max_possible, 0, -1):
        if total % m != 0:
            continue
        target = total // m
        if target < max_val:
            continue
        current_sums = [0] * m
        valid = True
        for num in arr:
            placed = False
            for i in range(m):
                if current_sums[i] + num <= target:
                    current_sums[i] += num
                    placed = True
                    break
            if not placed:
                valid = False
                break
        if valid and all(s == target for s in current_sums):
            return m
    return 1


# 测试用例
if __name__ == "__main__":    
    # 测试用例
    test_cases = [
        [6, 4, 3, 3, 2],
        [10, 8, 6, 4, 2],
        [7, 7, 7],
        [5, 4, 3, 2, 1],
        [5, 4, 3, 2],
    ]
    
    for i, test in enumerate(test_cases):
        print(f"测试用例 {i+1} {test}: 最大的m值为 {max_m(test)}")
